package cn.huanglei936.essay.thymeleaf.servlet;

import cn.huanglei936.essay.thymeleaf.api.ucenter.Client;
import cn.huanglei936.essay.thymeleaf.api.ucenter.XMLHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedList;

@WebServlet(urlPatterns = "/test/*")
public class TestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(" >>>>>> test doGet ");

        String userName = "user";
        String pwd = "ffffff";
        Client e = new Client();
        String result = e.uc_user_login(userName, pwd);
        String $ucsynlogin = "";
        LinkedList<String> rs = XMLHelper.uc_unserialize(result);
        if (rs.size() > 0) {
            int $uid = Integer.parseInt(rs.get(0));
            String $username = rs.get(1);
            String $password = rs.get(2);
            String $email = rs.get(3);
            if ($uid > 0) {
                $ucsynlogin = e.uc_user_synlogin($uid);
                System.out.println("$ucsynlogin = " + $ucsynlogin);
            }
            else if ($uid == -1) {
                System.out.println("用户不存在,或者被删除");
            }
            else if ($uid == -2) {
                System.out.println("密码错");
            }
            else {
                System.out.println("未定义");
            }
        }
        else {
            System.out.println("Login failed");
            System.out.println(result);
        }

        super.doGet(req, resp);
    }
}
